<template>
  <div class="goods">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="line-height: 36px;">货品管理</span>
        <el-button style="float: right;" type="primary" @click="dialogOpen('add')" v-if="USER.auth.indexOf('base_goods_add')!==-1">新增货品</el-button>
      </div>
      <s-table
        :table="table"
        @http="tableWatch">
        <el-table-column
          fixed="right"
          align="center"
          slot="operation"
          class-name="operationMore"
          label="操作"
          width="80">
          <template scope="s">
            <el-button type="info" icon="edit" size="mini" @click="dialogOpen('PUT', s.row)" v-if="USER.auth.indexOf('base_goods_edit')!==-1"></el-button>
          </template>
        </el-table-column>
        <el-form-item label="货品名称" prop="mc">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_mc"
                    placeholder="货品名称" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="货品编号" prop="bh">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_bh"
                    placeholder="货品编号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="种类名称" prop="zlmc">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_zlmc"
                    placeholder="种类名称" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
      </s-table>
    </el-card>
    <s-dialog :dialog="dialog" :close="dialogInit">
      <p slot="title">{{dialog.title}}货品</p>
      <el-tabs v-model="dialog.activeName">
        <el-tab-pane label="主信息" name="1" disabled>
          <s-form :form="formDialog1" ref="formDialog1">
            <el-row>
              <el-col :xs="24" :lg="{span: 5, offset: 0}" class="">
                <el-form-item prop="bh" label="货品编号">
                  <el-input
                    type="text"
                    v-model="formDialog1.bh"
                    placeholder="货品编号"></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                <el-form-item prop="mc" label="货品名称">
                  <el-input
                    type="text"
                    v-model="formDialog1.mc"
                    placeholder="货品名称"></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                <el-form-item label="货主名称">
                  <div class="s-content">
                    <el-tag type="success">{{USER.hz[0]? USER.hz[0].show_hzid : '暂无货主'}}</el-tag>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                <el-form-item prop="zlid" label="种类名称">
                  <el-select v-model="formDialog1.zlid"
                             filterable
                             remote
                             placeholder="请选择种类名称"
                             :remote-method="dialogRemoteZlmc">
                    <el-option
                      v-for="item in dialog.zlid"
                      :key="item.id"
                      :label="item.mc"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :xs="24" :lg="{span: 5, offset: 0}" class="">
                <el-form-item prop="tm" label="货品条码">
                  <el-input
                    type="text"
                    v-model="formDialog1.tm"
                    placeholder="货品条码"></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                <el-form-item prop="bzid" label="包装" v-if="dialog.title === '新增'">
                  <el-select v-model="formDialog1.bzid"
                             filterable
                             remote
                             placeholder="请选择包装"
                             @change="dialogRemoteBzid"
                             :remote-method="dialogRemoteBzmc">
                    <el-option
                      v-for="item in dialog.bzid"
                      :key="item.id"
                      :label="item.bzmc"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="包装" v-else>
                  <div class="s-content">{{dialog.row.bzmc}}</div>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                <el-form-item prop="bkxs" label="是否不可销售">
                  <el-select v-model="formDialog1.bkxs" placeholder="请选择">
                    <el-option
                      v-for="item in GOODS.bkxs"
                      :key="item.dictionaryid"
                      :label="item.value"
                      :value="item.dictionaryid">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                <el-form-item prop="cjsn" label="是否采集SN码">
                  <el-select v-model="formDialog1.cjsn" placeholder="请选择">
                    <el-option
                      v-for="item in GOODS.cjsn"
                      :key="item.dictionaryid"
                      :label="item.value"
                      :value="item.dictionaryid">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :xs="24" :lg="{span: 5, offset: 0}" class="">
                <el-form-item prop="sfyx" label="是否有效">
                  <el-select v-model="formDialog1.sfyx" placeholder="请选择">
                    <el-option
                      v-for="item in GOODS.sfyx"
                      :key="item.dictionaryid"
                      :label="item.value"
                      :value="item.dictionaryid">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                <el-form-item prop="zhhp" label="是否组合货品">
                  <el-select v-model="formDialog1.zhhp" placeholder="请选择">
                    <el-option
                      v-for="item in GOODS.zhhp"
                      :key="item.dictionaryid"
                      :label="item.value"
                      :value="item.dictionaryid">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 5, offset: 1}" class="" v-if="this.dialog.zjfs === '1'">
                <el-form-item prop="zjgzid" label="质检规则">
                  <el-select v-model="formDialog1.zjgzid"
                             filterable
                             remote
                             placeholder="请选择质检规则"
                             :remote-method="dialogRemoteZjmc">
                    <el-option
                      v-for="item in dialog.zjgzid"
                      :key="item.id"
                      :label="item.mc"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                <el-form-item prop="kczdl" label="库存数量最大预警" v-if="this.dialog.kcyj ==='1'">
                  <el-input
                    type="text"
                    v-model="formDialog1.kczdl"
                    placeholder="库存数量最大预警"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :xs="24" :lg="{span: 5, offset: 0}" class="">
                <el-form-item prop="kczxl" label="库存最小数量预警" v-if="this.dialog.kcyj ==='1'">
                  <el-input
                    type="text"
                    v-model="formDialog1.kczxl"
                    placeholder="库存最小数量预警"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </s-form>
        </el-tab-pane>
        <el-tab-pane label="有效期" name="2" disabled>
          <s-form :form="formDialog2" ref="formDialog2">
            <el-row>
              <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
                <el-form-item prop="yxqkz" label="有效期控制">
                  <el-select v-model="formDialog2.yxqkz" placeholder="请选择">
                    <el-option
                      v-for="item in GOODS.yxqkz"
                      :key="item.dictionaryid"
                      :label="item.value"
                      :value="item.dictionaryid">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 11, offset: 1}" class="" v-if="this.formDialog2.yxqkz ==='1'">
                <el-form-item prop="zqlx" label="周期类型">
                  <el-select v-model="formDialog2.zqlx" placeholder="请选择">
                    <el-option
                      v-for="item in GOODS.zqlx"
                      :key="item.dictionaryid"
                      :label="item.value"
                      :value="item.dictionaryid">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :xs="24" :lg="{span: 11, offset: 0}" class="" v-if="this.formDialog2.yxqkz ==='1'">
                <el-form-item prop="yxq" label="有效期">
                  <el-input-number
                    :min="1"
                    type="text"
                    v-model="formDialog2.yxq"
                    placeholder="有效期"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 11, offset: 1}" class="" v-if="this.formDialog2.yxqkz ==='1'">
                <el-form-item prop="sxqyj" label="失效期预警">
                  <el-input-number
                    :min="1"
                    :max="formDialog2.yxq"
                    type="text"
                    v-model="formDialog2.sxqyj"
                    placeholder="有效期"></el-input-number>
                </el-form-item>
              </el-col>
            </el-row>
          </s-form>
        </el-tab-pane>
        <el-tab-pane label="拣货位" name="3" disabled>
          <s-form :form="formDialog30" ref="formDialog30">
            <el-row v-if="dialog.sfbh === '1'">
              <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
                <el-form-item prop="bhsx" label="补货上限">
                  <el-input
                    type="text"
                    v-model="formDialog30.bhsx"
                    placeholder="补货上限"></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 11, offset: 1}" class="">
                <el-form-item prop="ccqbh" label="从存储区补货">
                  <el-select v-model="formDialog30.ccqbh" placeholder="请选择">
                    <el-option
                      v-for="item in GOODS.ccqbh"
                      :key="item.dictionaryid"
                      :label="item.value"
                      :value="item.dictionaryid">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="dialog.sfbh === '1'">
              <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
                <el-form-item prop="bhdw" label="补货单位">
                  <el-select v-model="formDialog30.bhdw" placeholder="请选择">
                    <el-option
                      v-for="item in GOODS.bhdw"
                      :key="item.dictionaryid"
                      :label="item.value"
                      :value="item.dictionaryid">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :lg="{span: 11, offset: 1}" class="">
                <el-form-item prop="xjhwbh" label="从箱捡区补货">
                  <el-select v-model="formDialog30.xjhwbh" placeholder="请选择">
                    <el-option
                      v-for="item in GOODS.xjhwbh"
                      :key="item.dictionaryid"
                      :label="item.value"
                      :value="item.dictionaryid">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="dialog.sfbh === '1' && formDialog30.bhdw == 1">
              <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
                <el-form-item prop="qzfs" label="取整方式">
                  <el-select v-model="formDialog30.qzfs" placeholder="请选择">
                    <el-option
                      v-for="item in GOODS.qzfs"
                      :key="item.dictionaryid"
                      :label="item.value"
                      :value="item.dictionaryid">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-collapse>
                <el-collapse-item title="主单位" name="1">
                  <s-form :form="formDialog31" ref="formDialog31">
                    <el-row>
                      <el-col :xs="24" :lg="{span: 5, offset: 0}" class="">
                        <el-form-item prop="zdwsl" label="数量">
                          <el-input
                            disabled
                            type="text"
                            v-model="formDialog31.zdwsl"
                            placeholder="数量"></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                        <el-form-item prop="ms" label="包装描述">
                          <el-input
                            disabled
                            type="text"
                            v-model="formDialog31.ms"
                            placeholder="包装描述"></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                        <el-form-item prop="jhwzlx" label="主单位库位使用类型">
                          <el-select
                            v-model="formDialog31.jhwzlx"
                            @change="dialogChangeLibrarys1"
                            placeholder="请选择">
                            <el-option
                              v-for="item in GOODS.jhwzlx"
                              :key="item.dictionaryid"
                              :label="item.value"
                              :value="item.dictionaryid">
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :xs="24" :lg="{span: 5, offset: 1}" class="" v-if="formDialog31.jhwzlx != 0">
                        <el-form-item prop="zkwid" label="主单位库位">
                          <el-select v-model="formDialog31.zkwid"
                                     filterable
                                     remote
                                     placeholder="请选择库位"
                                     :remote-method="dialogRemoteLibrarys1">
                            <el-option
                              v-for="item in dialog.librarys1"
                              :key="item.id"
                              :label="item.mc"
                              :value="item.id">
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </s-form>
                </el-collapse-item>
                <el-collapse-item title="内包装" name="2">
                  <s-form :form="formDialog32" ref="formDialog32">
                    <el-row>
                      <el-col :xs="24" :lg="{span: 5, offset: 0}" class="">
                        <el-form-item prop="zdwsl" label="数量">
                          <el-input
                            disabled
                            type="text"
                            v-model="formDialog32.zdwsl"
                            placeholder="数量"></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                        <el-form-item prop="ms" label="包装描述">
                          <el-input
                            disabled
                            type="text"
                            v-model="formDialog32.ms"
                            placeholder="包装描述"></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                        <el-form-item prop="jhwnlx" label="内包装库位使用类型">
                          <el-select
                            v-model="formDialog32.jhwnlx"
                            @change="dialogChangeLibrarys2"
                            placeholder="请选择">
                            <el-option
                              v-for="item in GOODS.jhwnlx"
                              :key="item.dictionaryid"
                              :label="item.value"
                              :value="item.dictionaryid">
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :xs="24" :lg="{span: 5, offset: 1}" class=""  v-if="formDialog32.jhwnlx != 0">
                        <el-form-item prop="zkwid" label="内包装库位">
                          <el-select v-model="formDialog32.zkwid"
                                     filterable
                                     remote
                                     placeholder="请选择库位"
                                     :remote-method="dialogRemoteLibrarys2">
                            <el-option
                              v-for="item in dialog.librarys2"
                              :key="item.id"
                              :label="item.mc"
                              :value="item.id">
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </s-form>
                </el-collapse-item>
                <el-collapse-item title="箱" name="3">
                  <s-form :form="formDialog33" ref="formDialog33">
                    <el-row>
                      <el-col :xs="24" :lg="{span: 5, offset: 0}" class="">
                        <el-form-item prop="zdwsl" label="数量">
                          <el-input
                            disabled
                            type="text"
                            v-model="formDialog33.zdwsl"
                            placeholder="数量"></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                        <el-form-item prop="ms" label="包装描述">
                          <el-input
                            disabled
                            type="text"
                            v-model="formDialog33.ms"
                            placeholder="包装描述"></el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                        <el-form-item prop="jhxnlx" label="箱包装库位使用类型">
                          <el-select
                            v-model="formDialog33.jhxnlx"
                            @change="dialogChangeLibrarys3"
                            placeholder="请选择">
                            <el-option
                              v-for="item in GOODS.jhxnlx"
                              :key="item.dictionaryid"
                              :label="item.value"
                              :value="item.dictionaryid">
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :xs="24" :lg="{span: 5, offset: 1}" class="" v-if="formDialog33.jhxnlx != 0">
                        <el-form-item prop="xkwid" label="箱包装库位">
                          <el-select v-model="formDialog33.xkwid"
                                     filterable
                                     remote
                                     placeholder="请选择库位"
                                     :remote-method="dialogRemoteLibrarys3">
                            <el-option
                              v-for="item in dialog.librarys3"
                              :key="item.id"
                              :label="item.mc"
                              :value="item.id">
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </s-form>
                </el-collapse-item>
              </el-collapse>
            </el-row>
          </s-form>
        </el-tab-pane>
        <el-tab-pane label="供应商" name="4" disabled>
          <el-card>
            <div slot="header" class="clearfix">
              <s-form :form="formDialog4" ref="formDialog4">
                <el-row>
                  <el-col :xs="24" :lg="{span: 5, offset: 0}" class="">
                    <el-form-item prop="gysid" label="供应商">
                      <el-select v-model="formDialog4.gysid"
                                 filterable
                                 remote
                                 placeholder="请选择供应商名称"
                                 @change="dialogSupplierGysid"
                                 :remote-method="dialogRemoteGysmc">
                        <el-option
                          v-for="item in dialog.gysid"
                          :key="item.id"
                          :label="item.mc"
                          :value="item.id">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :xs="24" :lg="{span: 5, offset: 1}" class="">
                    <el-form-item prop="yxj" label="优先级">
                      <el-input-number
                        :min="1"
                        :max="tableSupplier.data.length + dialog.formDialog4.maxAdd"
                        v-model="formDialog4.yxj"
                        placeholder="优先级"></el-input-number>
                    </el-form-item>
                  </el-col>
                  <el-col :xs="12" :lg="{span: 4, offset: 1}" class="">
                    <el-form-item prop="sfjh" label="激活">
                      <div class="s-content">
                        <el-switch
                          v-model="formDialog4.sfjh"
                          on-color="#13ce66"
                          on-text="是"
                          off-text="否"
                          off-color="#ff4949"
                          on-value="1"
                          off-value="0">
                        </el-switch>
                      </div>
                    </el-form-item>
                  </el-col>
                  <el-col :xs="12" :lg="{span: 5, offset: 0}" class="">
                    <el-form-item label="可用操作">
                      <div class="s-content">
                        <el-button type="info" size="small" @click="formDialog4SupplierSave" v-if="dialog.formDialog4.isAdd">保存</el-button>
                        <div v-else>
                          <el-button type="success" size="small" @click="formDialog4SupplierEdit">修改</el-button>
                          <el-button type="danger" :plain="true" size="small" @click="formDialog4SupplierCancel">取消</el-button>
                        </div>
                      </div>
                    </el-form-item>
                  </el-col>
                </el-row>
              </s-form>
            </div>
            <s-table :table="tableSupplier" ref="tableSupplier" :pagination="false" :expand="false" :control="false">
              <el-table-column
                fixed="right"
                align="center"
                slot="operation"
                class-name="operationMore"
                label="操作"
                width="80">
                <template scope="s">
                  <el-button type="info" icon="edit" size="mini" @click="tableSupplierEdit(s.row)"></el-button>
                  <el-button type="danger" icon="delete" size="mini" @click="tableSupplierDelete(s.row)"></el-button>
                </template>
              </el-table-column>
            </s-table>
          </el-card>
        </el-tab-pane>
        <el-tab-pane label="配件" name="5" disabled>
          <el-card>
            <div slot="header" class="clearfix">
              <s-form :form="formDialog5" ref="formDialog5">
                <el-col :xs="24" :lg="{span: 6, offset: 0}" class="">
                  <el-form-item prop="hpid" label="货品">
                    <el-select v-model="formDialog5.hpid"
                               filterable
                               remote
                               placeholder="请选择货品名称"
                               @change="dialogPartsHpid"
                               :remote-method="dialogRemoteHp">
                      <el-option
                        v-for="item in dialog.hpid"
                        :key="item.id"
                        :label="item.mc"
                        :value="item.id">
                      </el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :lg="{span: 6, offset: 1}" class="">
                  <el-form-item prop="sl" label="数量">
                    <el-input
                      type="text"
                      v-model.number="formDialog5.sl"
                      placeholder="数量"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :xs="24" :lg="{span: 6, offset: 1}" class="">
                  <el-form-item label="配件保存">
                    <div class="s-content">
                      <el-button type="info" size="small" @click="dialogPartsSave">保存</el-button>
                    </div>
                  </el-form-item>
                </el-col>
              </s-form>
            </div>
            <s-table :table="tableParts" ref="tableParts" :expand="false">
            </s-table>
          </el-card>
        </el-tab-pane>
      </el-tabs>
      <el-button slot="footer" v-if="dialog.activeName !== '1'" @click="dialogPre">上一页</el-button>
      <el-button slot="footer" type="info" v-if="dialog.activeName !== '5'" @click="dialogNext">下一页</el-button>
      <el-button slot="footer" type="success" v-if="dialog.activeName === '5'" @click="dialogSave">保存</el-button>
    </s-dialog>
  </div>
</template>

<script>
  import {AutoVue, AutoPromise} from '~/plugins/Tools';
  function __form1 () {
    return {
      bh: {value: '', rule: ['vNull'], cRemarks: '货品编号'},
      mc: {value: '', rule: ['vNull'], cRemarks: '货品名称'},
      zlid: {value: '', rule: ['vNull__change'], cRemarks: '货品种类ID'},
      zjgzid: {value: '', rule: ['vNull__change'], cRemarks: '质检规则ID'},
      tm: {value: '', rule: ['vNull'], cRemarks: '货品条码'},
      bzid: {value: '', rule: ['vNull__change'], cRemarks: '包装ID '},
      bkxs: {value: '1', rule: ['vNull__change'], cRemarks: '是否不可销售'},
      cjsn: {value: '0', rule: ['vNull__change'], cRemarks: '是否采集SN码'},
      sfyx: {value: '1', rule: ['vNull__change'], cRemarks: '是否有效'},
      zhhp: {value: '1', rule: ['vNull__change'], cRemarks: '是否组合货品 0不组合 1组合'},
      kczdl: {value: '', rule: ['vNull'], cRemarks: '库存数量最大预警'},
      kczxl: {value: '', rule: ['vNull'], cRemarks: '库存最小数量预警'},
    };
  }
  function __form2 () {
    return {
      yxqkz: {value: '1', rule: ['vNull__change'], cRemarks: '有效期控制'},
      zqlx: {value: '0', rule: ['vNull__change'], cRemarks: '周期类型'},
      yxq: {value: 0, rule: ['vNull', 'vNumber', 'vNumberZ', 'vNumberZZ'], cRemarks: '有效期'},
      sxqyj: {value: 0, rule: ['vNull', 'vNumber', 'vNumberZ', 'vNumberZZ'], cRemarks: '失效期预警'},
    };
  }
  function __form3 () {
    return {
      sjgzid: {value: '1', rule: ['vNull'], cRemarks: ''},
      zzgzIds: {value: '1', rule: ['vNull'], cRemarks: ''},
    };
  }
  function __form30 () {
    return {
      bhsx: {value: '', rule: ['vNull', 'vNumber', 'vNumberZ', 'vNumberZZ'], cRemarks: '补货上限'},
      bhdw: {value: '1', rule: ['vNull__change'], cRemarks: '补货单位'},
      ccqbh: {value: '1', rule: ['vNull__change'], cRemarks: '从存储区补货'},
      xjhwbh: {value: '1', rule: ['vNull__change'], cRemarks: '从箱捡区补货'},
      qzfs: {value: '1', rule: ['vNull__change'], cRemarks: '取整方式'},
    };
  }
  function __form31 () {
    return {
      zdwsl: {value: '1', rule: ['vNull', 'vNumber'], cRemarks: '数量'},
      ms: {value: '1', rule: ['vNull'], cRemarks: '包装描述'},
      jhwzlx: {value: '0', rule: ['vNull__change'], cRemarks: '主单位库位使用类型'},
      zkwid: {value: '', rule: ['vNull__change'], cRemarks: '主单位库位ID'},
    };
  }
  function __form32 () {
    return {
      zdwsl: {value: '1', rule: ['vNull', 'vNumber'], cRemarks: '数量'},
      ms: {value: '1', rule: ['vNull'], cRemarks: '包装描述'},
      jhwnlx:
        {
          value: '0',
          rule: ['vNull__change'],
          cRemarks: '内包装库位使用类型',
        },
      zkwid: {value: '', rule: ['vNull__change'], cRemarks: '内包装库位ID'},
    };
  }
  function __form33 () {
    return {
      zdwsl: {value: '1', rule: ['vNull', 'vNumber'], cRemarks: '数量'},
      ms: {value: '1', rule: ['vNull'], cRemarks: '包装描述'},
      jhxnlx:
        {
          value: '0',
          rule: ['vNull__change'],
          cRemarks: '箱包装库位使用类型',
        },
      xkwid: {value: '', rule: ['vNull__change'], cRemarks: '箱包装库位ID'},
    };
  }
  function __form4 () {
    return {
      gysid: {value: '', rule: ['vNull__change'], cRemarks: ''},
      mc: {value: '', rule: ['vNull'], cRemarks: ''},
      sfjh: {value: '1', rule: ['vNull'], cRemarks: ''},
      yxj: {value: 1, rule: ['vNull'], cRemarks: ''},
    };
  }
  function __form5 () {
    return {
      hpid: {value: '', rule: ['vNull__change'], cRemarks: ''},
      sl: {value: 0, rule: ['vNull', 'vNumber', 'vNumberZ', 'vNumberZZ'], cRemarks: ''},
    };
  }
  export default AutoVue({
    name: 'base_goods-FEcarWms',
    data: {
      table: {
        column: [
          {
            label: '货品编号',
            prop: 'bh',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '货品名称',
            prop: 'mc',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '包装名称',
            prop: 'bzmc',
            minWidth: '0px',
            cRemarks: '',
            search: false,
          },
          {
            label: '种类名称',
            prop: 'zlmc',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '有效期',
            prop: 'yxq',
            minWidth: '0px',
            cRemarks: '有效期 单位为天',
            search: false,
          },
          {
            label: '组合货品',
            prop: 'show_zhhp',
            minWidth: '0px',
            cRemarks: '是否为组合货品 是否为组合货品 0否 1是',
            search: false,
          },
          {
            label: '是否不可销售',
            prop: 'show_bkxs',
            minWidth: '0px',
            cRemarks: '是否不可销售 是否不可销售 0否 1是',
            search: false,
          },
          {
            label: '采集SN码',
            prop: 'show_cjsn',
            minWidth: '0px',
            cRemarks: '是否采集SN码 是否采集SN码 0否 1是',
            search: false,
          },
          {
            label: '补货上限',
            prop: 'bhsx',
            minWidth: '0px',
            cRemarks: '',
            search: false,
          },
          {
            label: '是否有效',
            prop: 'show_sfyx',
            minWidth: '0px',
            cRemarks: '是否有效 是否有效 0无效 1有效',
            search: false,
          },
          {
            label: '有效期控制',
            prop: 'show_yxqkz',
            minWidth: '0px',
            cRemarks: '有效期控制',
            search: false,
          },
          {
            label: '周期类型',
            prop: 'show_zqlx',
            minWidth: '0px',
            cRemarks: '周期类型',
            search: false,
          },
          {
            label: '货主名称',
            prop: 'hzmc',
            minWidth: '0px',
            cRemarks: '',
            search: true},
          {
            label: '失效期预警',
            prop: 'sxqyj',
            minWidth: '0px',
            cRemarks: '失效期预警',
            search: false,
          },
        ],
        url: '/wmsgoods/list',
        key: 'id',
        tableColumn: 4,
        muti: false,
      },
      tableSupplier: {
        column: [
          {
            label: '优先级',
            prop: 'yxj',
            minWidth: '0px',
            search: false,
          },
          {
            label: '编号',
            prop: 'bh',
            minWidth: '0px',
            search: false,
          },
          {
            label: '名称',
            prop: 'mc',
            minWidth: '0px',
            search: false,
          },
          {
            label: '激活',
            prop: 'sfjh',
            minWidth: '0px',
            elTag: {
              filterType: function (value) {
                return parseInt(value) === 0 ? 'danger' : 'success';
              },
            },
            formatter: (row, column) => {
              return parseInt(row[column.property || column]) === 0 ? '未激活' : '激活';
            },
            search: false,
          },
        ],
        key: 'bh',
        tableColumn: 4,
        muti: false,
      },
      tableParts: {
        column: [
          {
            label: '货主名称',
            prop: 'hzmc',
            minWidth: '0px',
            search: true,
          },
          {
            label: '货主编号',
            prop: 'bh',
            minWidth: '0px',
            search: true,
          },
          {
            label: '数量',
            prop: 'sl',
            minWidth: '0px',
            search: false,
          },
          {
            label: '货品名称',
            prop: 'mc',
            minWidth: '0px',
            search: true,
          },
        ],
        tableColumn: 4,
        muti: false,
      },
      formDialog1: __form1(),
      formDialog2: __form2(),
      formDialog3: __form3(),
      formDialog30: __form30(),
      formDialog31: __form31(),
      formDialog32: __form32(),
      formDialog33: __form33(),
      formDialog4: __form4(),
      formDialog5: __form5(),
      dialog: {
        title: '新增',
        size: 'large',
        row: {},
        activeName: '1',
        zlid: [],
        zjgzid: [],
        gysid: [],
        hpid: '',
        bzid: [],
        gys: {},
        hp: [],
        librarys1: [],
        librarys2: [],
        librarys3: [],
        formDialog4: {
          isAdd: true,
          row: {},
          maxAdd: 1,
        },
        kcyj: {
        },
        ownerZjfs: {},
      },
    },
    transition: 'slide-fade',
    store: ['GOODS', 'USER', 'DICTIONARY_goods'],
    methods: {
      dialogInit () {
        this.dialog.title = '新增';
        this.dialog.row = {};
        this.dialog.activeName = '1';
        this.dialog.zlid = [];
        this.dialog.gysid = [];
        this.dialog.hpid = '';
        this.dialog.bzid = [];
        this.dialog.gys = {};
        this.dialog.hp = [];
        this.dialog.librarys1 = [];
        this.dialog.librarys2 = [];
        this.dialog.librarys3 = [];
        this.formDialog1 = {
          ...this.formDialog1,
          ...this.ObjectClone(__form1()),
        };
        this.formDialog3 = {
          ...this.formDialog3,
          ...this.ObjectClone(__form3()),
        };
        this.formDialog4 = {
          ...this.formDialog4,
          ...this.ObjectClone(__form4()),
        };
        this.formDialog5 = {
          ...this.formDialog5,
          ...this.ObjectClone(__form5()),
        };
        this.resetFields('formDialog1');
        this.resetFields('formDialog3');
        this.resetFields('formDialog4');
        this.tableClear('tableSupplier');
        this.resetFields('formDialog5');
        this.tableClear('tableParts');
      },
      async dialogOpen (type, more) {
        if (type) {
          type = type.toUpperCase();
        } else return;
        switch (type) {
        case 'ADD':
          await AutoPromise([
            async () => {
              if (!this.DICTIONARY_goods) {
                await this.USE('DICTIONARY_goods');
              }
            },
            async () => {
              await this.dialogRemoteZlmc('');
            },
            async () => {
              await this.dialogRemoteBzmc('');
            },
            async () => {
              await this.dialogRemoteGysmc('');
            },
            async () => {
              await this.dialogRemoteHp('');
            },
            async () => {
              await this.dialogRemoteZjmc('');
            },
            async () => {
              await this.dialogRemoteLibrarys1('');
            },
            async () => {
              await this.dialogRemoteLibrarys2('');
            },
            async () => {
              await this.dialogRemoteLibrarys3('');
            },
            async () => {
              this.dialog.goodsHz = await this.post('/wmsgoods/seachOwnerXx');
              this.dialog.kcyj = this.dialog.goodsHz.contentList[0].kcyj;
              this.dialog.zjfs = this.dialog.goodsHz.contentList[0].zjfs;
              this.dialog.sfbh = this.dialog.goodsHz.contentList[0].sfbh;
            },
          ]);
          this.dialog.title = '新增';
          break;
        case 'PUT':
          more.yxq = parseInt(more.yxq);
          more.sxqyj = parseInt(more.sxqyj);
          this.dialog.row = more;
          this.dialog.title = '修改';
          this.formDialog1 = {
            ...this.formDialog1,
            ...this.ObjectClone(__form1(), more),
          };
          this.formDialog2 = {
            ...this.formDialog2,
            ...this.ObjectClone(__form2(), more),
          };
          this.formDialog3 = {
            ...this.formDialog3,
            ...this.ObjectClone(__form3(), more),
          };
          await AutoPromise([
            async () => {
              if (!this.DICTIONARY_goods) {
                await this.USE('DICTIONARY_goods');
              }
            },
            async () => {
              await this.dialogRemoteZlmc('');
            },
            async () => {
              await this.dialogRemoteBzmc('');
            },
            async () => {
              await this.dialogRemoteGysmc('');
            },
            async () => {
              await this.dialogRemoteHp('');
            },
            async () => {
              await this.dialogRemoteLibrarys1('');
            },
            async () => {
              await this.dialogRemoteLibrarys2('');
            },
            async () => {
              await this.dialogRemoteLibrarys3('');
            },
            async () => {
              let {contentList, totals} = await this.get('/wmsgoods/getAccessoriesByHpid/' + more.id);
              this.tableParts.data = contentList;
              this.tableParts.totals = totals;
            },
            async () => {
              let {contentList, totals} = await this.get('/wmsgoods/getSuppliersByHpid/' + more.id);
              this.tableSupplier.data = contentList;
              this.tableSupplier.totals = totals;
            },
          ]);
          this.dialog.row = more;
          break;
        }
        this.dialog.visible = true;
      },
      dialogPre () {
        this.dialog.activeName = parseInt(this.dialog.activeName) - 1 + '';
      },
      async dialogNext () {
        switch (this.dialog.activeName) {
        case '3':
          this.VALIDATE('formDialog30', option => {
            this.VALIDATE('formDialog31', option => {
              this.VALIDATE('formDialog32', option => {
                this.VALIDATE('formDialog33', option => {
                  this.dialog.activeName = '4';
                });
              });
            });
          });
          break;
        case '4':
          if (this.tableSupplier.data.length > 0) {
            this.dialog.activeName = '5';
          } else {
            this.$alert('请您选择至少一个供应商！', '提示');
          }
          break;
        default :this.VALIDATE('formDialog' + this.dialog.activeName, option => {
          this.dialog.activeName = parseInt(this.dialog.activeName) + 1 + '';
        });
        }
      },
      async dialogRemoteZlmc (query) {
        this.dialog.zlid = await this.post('/wmsgoodstype/getWmsGoodsTypeByHzId', {mc: query});
      },
      async dialogRemoteZjmc (query) {
        this.dialog.zjgzid = await this.post('/wmsqualitytesting/selectZjgzBymc', {mc: query});
      },
      async dialogRemoteBzmc (query) {
        let {contentList} = await this.post('/wmspacking/getWmsPackingBySshzid', {mc: query});
        this.dialog.bzid = contentList;
      },
      async dialogRemoteBzid (id) {
        if (!id) return;
        let {list} = await this.get('/wmspacking/getWmsPacking/' + id);
        for (let i = 0; i < 3; i++) {
          let form = 'formDialog3' + (i + 1);
          list.forEach(value => {
            if (parseInt(value.bzlx) === i) {
              this[form].ms = value.ms;
              this[form].zdwsl = value.zdwsl;
            }
          });
        }
      },
      async dialogRemoteGysmc (query) {
        let {contentList} = await this.post('/wmsownersupplier/getWmsOwnerSupplierByHzId', {mc: query});
        this.dialog.gysid = contentList;
      },
      async dialogRemoteHp (query) {
        let {contentList} = await this.post('/wmsgoods/getGoodsBySshzid', {mc: query});
        this.dialog.hpid = contentList;
      },
      async dialogRemoteLibrarys1 (query) {
        let {contentList} = await this.post('/wmslibraryposition/getZCLibrarysBymc', {mc: query, lx: this.formDialog31.jhwzlx});
        this.dialog.librarys1 = contentList;
      },
      async dialogRemoteLibrarys2 (query) {
        let {contentList} = await this.post('/wmslibraryposition/getZCLibrarysBymc', {mc: query, lx: this.formDialog32.jhwnlx});
        this.dialog.librarys2 = contentList;
      },
      async dialogRemoteLibrarys3 (query) {
        let {contentList} = await this.post('/wmslibraryposition/getZCLibrarysBymc', {mc: query, lx: this.formDialog33.jhxnlx});
        this.dialog.librarys3 = contentList;
      },
      async dialogChangeLibrarys1 (id) {
        this.formDialog31.zkwid = '';
        if (parseInt(id) !== 0) {
          this.dialogRemoteLibrarys1('');
        }
      },
      async dialogChangeLibrarys2 (id) {
        this.formDialog32.zkwid = '';
        if (parseInt(id) !== 0) {
          this.dialogRemoteLibrarys2('');
        }
      },
      async dialogChangeLibrarys3 (id) {
        this.formDialog33.xkwid = '';
        if (parseInt(id) !== 0) {
          this.dialogRemoteLibrarys3('');
        }
      },
      formDialog4SupplierInit () {
        this.dialog.formDialog4.isAdd = true;
        this.dialog.formDialog4.maxAdd = 1;
        this.dialog.formDialog4.row = {};
        this.resetFields('formDialog4');
        this.formDialog4 = {
          ...this.formDialog4,
          ...this.ObjectClone(__form4()),
        };
        this.formDialog4.yxj = this.tableSupplier.data.length + 1;
      },
      formDialog4SupplierSave () {
        this.VALIDATE('formDialog4', async option => {
          let check = true;
          this.tableSupplier.data.forEach((value, index) => {
            if (this.dialog.gys.id === value.id) {
              this.$alert('供应商已存在！位于优先级 ' + (index + 1), '提示');
              check = false;
            }
          });
          if (!check) return;
          let yxj = option.yxj;
          let index = -1;
          for (let i = 0; i < this.tableSupplier.data.length; i++) {
            if (this.tableSupplier.data[i].yxj === yxj) {
              if (index === -1) {
                index = i;
              }
              this.tableSupplier.data[i].yxj++;
              yxj++;
            }
          }
          let item = {
            ...option,
            ...this.dialog.gys,
          };
          if (index === -1) {
            this.tableSupplier.data.push(item);
          } else {
            this.tableSupplier.data.splice(index, 0, item);
          }
          this.formDialog4SupplierInit();
        });
      },
      formDialog4SupplierEdit () {
        this.VALIDATE('formDialog4', async option => {
          let check = true;
          this.tableSupplier.data.forEach((value, index) => {
            if (this.dialog.gys.id === value.id && value.id !== this.dialog.formDialog4.row.gysid) {
              this.$alert('供应商已存在！位于优先级 ' + (index + 1), '提示');
              check = false;
            }
          });
          if (!check) return;
          for (let i = this.dialog.formDialog4.row.yxj; i < this.tableSupplier.data.length; i++) {
            this.tableSupplier.data[i].yxj--;
          }
          this.tableSupplier.data.splice(this.dialog.formDialog4.row.yxj - 1, 1);

          let yxj = option.yxj;
          let index = -1;
          for (let i = 0; i < this.tableSupplier.data.length; i++) {
            if (this.tableSupplier.data[i].yxj === yxj) {
              if (index === -1) {
                index = i;
              }
              this.tableSupplier.data[i].yxj++;
              yxj++;
            }
          }
          let item = {
            ...option,
            ...this.dialog.gys,
          };
          if (index === -1) {
            this.tableSupplier.data.push(item);
          } else {
            this.tableSupplier.data.splice(index, 0, item);
          }

          this.formDialog4SupplierInit();
        });
      },
      formDialog4SupplierCancel () {
        this.formDialog4SupplierInit();
      },
      tableSupplierEdit (row) {
        this.dialog.formDialog4.isAdd = false;
        this.dialog.formDialog4.maxAdd = 0;
        this.dialog.formDialog4.row = Object.assign({}, row);
        this.formDialog4 = {
          ...this.formDialog4,
          ...this.ObjectClone(__form4(), row),
        };
      },
      tableSupplierDelete (row) {
        this.$confirm('您将删除选择的供应商 ' + row.mc, '确认删除？', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning',
        })
          .then(_ => {
            let yxj = row.yxj;
            for (let i = yxj; i < this.tableSupplier.data.length; i++) {
              this.tableSupplier.data[i].yxj--;
            }
            this.tableSupplier.data.splice(yxj - 1, 1);
            this.formDialog4.yxj = this.tableSupplier.data.length + this.dialog.formDialog4.maxAdd;
          });
      },
      async dialogSave () {
        if (this.dialog.title === '新增') {
          if (this.formDialog1.zhhp === '1' && this.tableParts.data.length < 1) {
            return this.$alert('在组合货品的情况下，配件不可以为空！', '提示');
          }
          let gys = [];
          for (let {gysid, sfjh, yxj} of this.tableSupplier.data) {
            gys.push({gysid, sfjh, yxj});
          }
          let pj = [];
          for (let {hpid, sl} of this.tableParts.data) {
            pj.push({hpid, sl});
          }
          let json = {
            ...this.FORMOPTION('formDialog1'),
            ...this.FORMOPTION('formDialog2'),
            ...this.FORMOPTION('formDialog3'),
            ...this.FORMOPTION('formDialog30'),
            ...this.FORMOPTION('formDialog31'),
            ...this.FORMOPTION('formDialog32'),
            ...this.FORMOPTION('formDialog33'),
            ...this.FORMOPTION('formDialog34'),
            gys,
            pj,
          };
          try {
            await this.post('/wmsgoods/add', json);
            this.dialogInit();
            this.tableWatch('table');
            this.dialog.visible = false;
          } catch (err) {
            console.log(err);
          }
        } else {
        }
      },
      dialogSupplierGysid (id) {
        this.dialog.gysid.forEach(value => {
          if (value.id === id) {
            this.dialog.gys = value;
          }
        });
      },
      dialogPartsHpid (id) {
        if (this.dialog.hpid) {
          this.dialog.hpid.forEach(value => {
            if (value.id === id) {
              this.dialog.hp = value;
            }
          });
        }
      },
      dialogPartsInit () {
        this.resetFields('formDialog5');// 重置form
        this.formDialog5 = {
          ...this.formDialog5,
          ...this.ObjectClone(__form5()),
        };// 重置table
      },
      dialogPartsSave () {
        this.VALIDATE('formDialog5', option => {
          let check = true;
          this.tableParts.data.forEach((value, index) => {
            if (this.dialog.hp.id === value.id) {
              this.$confirm(`发现货品 ${value.mc} 已经存在,是否合并？`, '提示', {
                confirmButtonText: '是',
                cancelButtonText: '否',
                type: 'warning',
              }).then(() => {
                this.tableParts.data[index].sl += option.sl;
                this.dialogPartsInit();
              });
              check = false;
            }
          });
          if (check) {
            this.tableParts.data.push({
              ...option,
              ...this.dialog.hp,
            });
            this.tableParts.total++;
            this.dialogPartsInit();
          }
        });
      },
    },
    mounted: function () {
      this.tableWatch('table');
      console.log(this);
    },
  });
</script>
<style scoped lang="scss">
  .box-card {
    margin: 20px;
  }

  .createTimeSpan {
    display: block;
    margin-top: 34px;
  }

  @media screen and (max-width: 800px) {
    .createTimeSpan {
      margin-top: 0;
    }
    .box-card {
      margin: 0;
    }
  }

  .el-select {
    width: 100%;
  }
</style>

<style lang="scss">

</style>
